// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: jshin

#pragma once

#include <cstdint>

#include "coin2/exchange/base/executor/lifecycle_timestamp.h"

namespace coin2::exchange::base::executor {

class ResetableUpdate {
 public:
  ResetableUpdate() = default;
  virtual ~ResetableUpdate() = default;
  virtual void Reset() = 0;
};

class TopicRecordUpdate : public ResetableUpdate {
 public:
  TopicRecordUpdate() : ResetableUpdate() {}
  ~TopicRecordUpdate() override = default;

  int64_t topic_id() const { return topic_id_; }
  int64_t sequence() const { return sequence_; }
  int64_t timestamp() const { return timestamp_; }
  const LifecycleTimestamp& ts() const {
    return ts_;
  }

 public:
  void Reset() override {
    ResetTopicRecordUpdate();
  }

  void ResetTopicRecordUpdate() {
    topic_id_ = 0;
    timestamp_ = 0;
    sequence_ = 0;
    ts_.Reset();
  }

  void SetTimestamp(int64_t timestamp) { timestamp_ = timestamp; }

  LifecycleTimestamp& MutableTs() {
    return ts_;
  }

 protected:
  int64_t topic_id_{0};
  int64_t timestamp_{0};
  int64_t sequence_{0};

  LifecycleTimestamp ts_;
};

class IPacketSubscriber {
 public:
  virtual void onBeginMarket(const TopicRecordUpdate& upd) = 0;
  virtual void onEndMarket(const TopicRecordUpdate& upd) = 0;
  virtual void onBeginPacket(const TopicRecordUpdate& upd) = 0;
  virtual void onEndPacket(const TopicRecordUpdate& upd) = 0;
  virtual ~IPacketSubscriber() = default;
};

}  // namespace coin2::exchange::base::executor
